package com.org.controller.annotation;

import com.org.entity.Poem;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Rainy-Heights
 * @version 1.0
 * @Date 2023/3/16 15:22
 */
@RestController()
@RequestMapping("/annotation")
public class RequestBody {

    //测试RequestBody,只能再post请求里实现
    @PostMapping("/postbody")
    @ResponseBody//响应体写在路由上
    public String testRequestBody(@Validated  Poem poem){
        System.out.println(poem);
        return poem.toString();
    }

    @RequestMapping("/requestParam")
    @ResponseBody
    public String testRequestParam(@RequestParam(value = "poem",required = true) Poem poem){
       return poem.getTitle();
    }
}
